<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <!--<a-form-item label="线别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['lineType']" placeholder="请输入线别"></a-input>
        </a-form-item>-->
        <a-form-item label="物料料号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-popup
            v-decorator="['materielCode']"
            :trigger-change="true"
            org-fields="materiel_code,gauge,product_name"
            dest-fields="materielCode,materielGague,materielName"
            code="materiel_search"
            @callback="popupCallback"/>
        </a-form-item>
        <a-form-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['materielName']" placeholder="请输入物料名称" disabled></a-input>
        </a-form-item>
        <a-form-item label="物料规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['materielGague']" placeholder="请输入物料规格" disabled></a-input>
        </a-form-item>
        <a-form-item label="设备序号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['deviceSerial']" placeholder="请输入设备序号"></a-input>
        </a-form-item>
        <a-form-item label="TABLE" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['materielTable']" placeholder="请输入TABLE"></a-input>
        </a-form-item>
        <a-form-item label="料站" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['materielStation']" placeholder="请输入料站"></a-input>
        </a-form-item>
        <a-form-item label="通道" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['passage']" placeholder="请输入通道"></a-input>
        </a-form-item>
        <a-form-item label="点位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['pointLocation']" placeholder="请输入点位"></a-input>
        </a-form-item>
        <a-form-item label="点数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['pointNum']" placeholder="请输入点数"></a-input>
        </a-form-item>
        <a-form-item label="TRAY盘物料" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="radio" v-decorator="['trayPlate']" :trigger-change="true" dictCode="yn" placeholder="请选择TRAY盘物料"/>
        </a-form-item>
        <a-form-item label="跳过标志" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="radio" v-decorator="['skipToken']" :trigger-change="true" dictCode="yn" placeholder="请选择跳过标志"/>
        </a-form-item>
        <a-form-item label="轨道" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['track']" placeholder="请输入轨道"></a-input>
        </a-form-item>
        <a-form-item label="主表ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['mainId']" placeholder="请输入主表ID"></a-input>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesOnlineMaterieltableModal",
    components: {
      JDictSelectTag,
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/produce/mesOnlineMaterieltableMain/addMesOnlineMaterieltable",
          edit: "/produce/mesOnlineMaterieltableMain/editMesOnlineMaterieltable",
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','sysOrgCode','lineType','materielCode','materielName','materielGague','deviceSerial','materielTable','materielStation','passage','pointLocation','pointNum','trayPlate','skipToken','track','query1','query2','query3','query4','query5','query6','mainId'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            formData['mainId'] = this.mainId
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','sysOrgCode','lineType','materielCode','materielName','materielGague','deviceSerial','materielTable','materielStation','passage','pointLocation','pointNum','trayPlate','skipToken','track','query1','query2','query3','query4','query5','query6','mainId'))
      },


    }
  }
</script>
